/*
 * Copyright (c) zhg2yqq.com Corp.
 * All Rights Reserved.
 */
package com.zhg2yqq.wheels.security.context;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;

import com.zhg2yqq.wheels.common.dto.CurrentUserDTO;

/**
 * @author zhg2yqq, 2022年12月3日
 * @version zhg2yqq v1.0
 */
public class SecurityUserHolder {
    public static CurrentUserDTO getUser() {
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        if (authentication != null && authentication.getPrincipal() instanceof CurrentUserDTO) {
            return (CurrentUserDTO) authentication.getPrincipal();
        }
        return null;
    }

    public static SecurityLoginUser getSecurityUser() {
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        if (authentication != null && authentication.getPrincipal() instanceof SecurityLoginUser) {
            return (SecurityLoginUser) authentication.getPrincipal();
        }
        return null;
    }
}
